package com.heima.wemedia.controller.v1;

import com.heima.apis.wemedia.MaterialManageControllerApi;
import com.heima.model.common.constants.wemedia.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController implements MaterialManageControllerApi {

    @Autowired
    private WmMaterialService materialService;


    /**
     * 文件上传接口
     *
     * @param multipartFile
     * @return
     */
    @PostMapping("/upload_picture")
    @Override
    public ResponseResult uploadPicture(@RequestBody MultipartFile multipartFile) {
        return materialService.uploadPicture(multipartFile);
    }

    /**
     * 素材列表
     *
     * @param dto
     * @return
     */
    @RequestMapping("/list")
    @Override
    public ResponseResult findList(@RequestBody WmMaterialDto dto) {
        return materialService.findList(dto);
    }

    /**
     * 删除图片
     *
     * @param id
     * @return
     */
    @GetMapping("/del_picture/{id}")
    @Override
    public ResponseResult delPicture(@PathVariable Integer id) {
        return materialService.delPicture(id);
    }

    /**
     * 取消收藏
     *
     * @param id
     * @return
     */
    @GetMapping("/cancel_collect/{id}")
    @Override
    public ResponseResult cancelCollectionMaterial(@PathVariable Integer id) {
        return materialService.updateStatus(id, WemediaConstants.IS_NO_COLLECTION);
    }

    /**
     * 收藏图片
     *
     * @param id
     * @return
     */
    @Override
    public ResponseResult collectionMaterial(Integer id) {
        return materialService.updateStatus(id, WemediaConstants.IS_COLLECTION);
    }
}